from rest_framework import serializers
from myapp.models import *


# 订单表
class OrderSer(serializers.ModelSerializer):

    user_name = serializers.SerializerMethodField()
    def get_user_name(self,obj):
       return obj.user_id.account

    address_name = serializers.SerializerMethodField()
    def get_address_name(self,obj):
        return obj.address_id.address

    class Meta:
        model = Order
        fields = "__all__"


# 订单商品表
class OrderGoodsSer(serializers.ModelSerializer):
    # user_name = serializers.SerializerMethodField()
    # def get_user_name(self,obj):
    #    return obj.user_id.username
    #
    # dishes_name = serializers.SerializerMethodField()
    # def get_dishes_name(self,obj):
    #     return obj.dishes_id.dishes_name
    #
    # merchant_name = serializers.SerializerMethodField()
    # def get_merchant_name(self,obj):
    #     return obj.merchant.username
    class Meta:
        model = OrderGoods
        fields = "__all__"